package com.windy.action.account;

import com.windy.action.BaseAction;
import com.windy.domain.account.User;
import com.windy.service.ServiceFactory;
import com.windy.service.interfaces.IAccountService;

public class RegisterAction extends BaseAction {

	private static final long serialVersionUID = -900318259579935439L;

	private User user;
	private String confrimPassword;

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public String getConfrimPassword() {
		return confrimPassword;
	}

	public void setConfrimPassword(String confrimPassword) {
		this.confrimPassword = confrimPassword;
	}

	@Override
	public String execute() throws Exception {
		IAccountService service = (IAccountService) ServiceFactory
				.getInstance().getService("accountServ");
		User existedUser = service.findUserByLoginName(user.getLoginName());
		
		if(existedUser != null)
		{
			this.addActionError("该用户名已被使用，请重新选用用户名！");
			return ERROR;
		}
		
		service.createUser(user);
		return SUCCESS;
	}

}
